#ifndef PLOG_MONOAPPENDER_LOGGER_H_
#define PLOG_MONOAPPENDER_LOGGER_H_

#include <memory>

#include "plog/logger.h"
#include "plog/log_message.h"
#include "plog/appender.h"

#include "plog/csv_formatter.h"

namespace plog
{
    class monoappender_logger 
        : public logger
    {
    public:
        monoappender_logger( appender* appender_instance /*takes ownership on appender_instance*/ )
            : appender_(appender_instance)
        { 
            if(   ( appender_.get() != NULL )
                && ( appender_->newly_created() ) )
            {
                csv_formatter   formatter;

                appender_->write( formatter.header(), formatter.header_size() );
            }
        }

        ~monoappender_logger(){};

        void write(const message& msg)
        {
            if( appender_.get() != NULL )
            {
                csv_formatter   formatter;
                formatter.format(msg);

                appender_->write( formatter.buffer(), formatter.length() );
            }
        }

        bool check_severity(log_level severity)
        {
            if( appender_.get() != NULL )
            {
                return (appender_->get_level() >= severity);
            }
            else
            {
                return false;
            }
        }

    private:
        std::auto_ptr<appender>     appender_;
    };
}

#endif //PLOG_MONOAPPENDER_LOGGER_H_